<template>
  <div>
    <CityHeader />
    <CitySearch :cities="cities" />
    <CityList :cities="cities" :hotCities="hotCities" :word="word" />
    <Alphabet :cities="cities" @change="changeAlphabetPosition" />
  </div>
</template>

<script>
import CityHeader from './components/CityHeader'
import CitySearch from './components/CitySearch'
import CityList from './components/CityList'
import Alphabet from './components/Alphabet'
import axios from 'axios'
export default {
  components: {
    CityHeader,
    CitySearch,
    CityList,
    Alphabet
  },
  data () {
    return {
      word: '',
      cities: {},
      hotCities: []
    }
  },
  methods: {
    getCityInfo () {
      axios.get('/api/city.json')
        .then(this.handleCityInfo)
    },
    handleCityInfo (res) {
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.cities = data.cities
        this.hotCities = data.hotCities
      }
    },
    changeAlphabetPosition (word) {
      this.word = word
    }
  },
  mounted () {
    this.getCityInfo()
  }
}
</script>

<style lang='stylus' rel='stylesheet/stylus' scoped>
</style>
